package com.ken.elmboot.service.impl;

import com.ken.elmboot.bean.Role;
import com.ken.elmboot.common.ElmException;
import com.ken.elmboot.common.Pager;
import com.ken.elmboot.mapper.RoleMapper;
import com.ken.elmboot.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ken
 */
@Service(value = "RoleService")
@Transactional(rollbackFor = ElmException.class)
public class RoleServiceImpl extends  DefaultServiceImpl<Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    public boolean add(Role object) {
        boolean ret = false;
        try {
            ret = roleMapper.add(object);
        } catch (Exception e) {
            throw new ElmException("新增异常", e);
        }
        return ret;
    }

    public boolean deleteById(Integer id) {

        boolean ret = false;
        try {
            ret = roleMapper.deleteById(id);
        } catch (Exception e) {
            throw new ElmException("删除异常", e);
        }
        return ret;
    }

    public boolean edit(Role object) {

        boolean ret = false;
        try {
            ret = roleMapper.edit(object);
        } catch (Exception e) {
            throw new ElmException("修改异常", e);
        }
        return ret;
    }

    public Role findById(Integer id) {
        Role ret = null;

        try {
            ret = roleMapper.findById(id);
        } catch (Exception e) {
            throw new ElmException("查询异常", e);
        }
        return ret;
    }

    public int findRoleotal(Pager<Role> pager) {

        int ret = 0;

        try {
            ret = roleMapper.findTotal(pager);
        } catch (Exception e) {
            throw new ElmException("查询异常", e);
        }
        return ret;
    }

    public List<Role> findByPager(Pager<Role> pager) {

        List<Role> ret = new ArrayList<Role>();

        try {
            ret = roleMapper.findByPager(pager);
        } catch (Exception e) {
            throw new ElmException("查询异常", e);
        }
        return ret;
    }

    public boolean deleteByIds(List<Integer> ids) {

        boolean ret = false;
        try {
            ret = roleMapper.deleteByIds(ids);
        } catch (Exception e) {
            throw new ElmException("删除异常", e);
        }
        return ret;
    }

}
